
import ModelMesh from "@/editor/domain/model/ModelMesh";
import MoldUtils from "@/editor/domain/utils/MoldUtils";
import KY3D from "@/editor/KY3D";
import { MDColor } from "@/libs/const/enum";
import BaseUtils from "../utils/BaseUtils";

export default class MeshHelper {
    
    static updateModel(vi:any[], data:IWallParams, uuid:string, color= MDColor.NORMALE_COLOR):ModelMesh {
        
        let entity: ModelMesh;
        if (uuid && uuid !== '') {
            entity = KY3D.SC.mesh.getMeshFormId(uuid);
            if (entity) {
                entity.updateMoldGeometry(vi[0], vi[1], vi[2], vi[3]);
            }
        }
        else {
            let molddata = BaseUtils.createModelData(vi[0], vi[1], vi[2], color, vi[4]);
            entity = new ModelMesh(molddata.geo, molddata.mat);
        }

        return entity;
    }

    static update0(data:IWallParams, uuid?:string, color?:any):ModelMesh {
        let vi = MoldUtils.getWallVI(data);
        return MeshHelper.updateModel(vi, data, uuid, color);
    }

    static update1(data:IWallParams, uuid?:string, color?:any):ModelMesh {
        let vi = MoldUtils.getBeamVI(data);
        return MeshHelper.updateModel(vi, data, uuid, color);
    }

    static update2(data:IWallParams, uuid?:string, color?:any):ModelMesh {
        let vi = MoldUtils.getPillarVI(data);
        return MeshHelper.updateModel(vi, data, uuid, color);
    }

    static update4(data:IWallParams, uuid?:string, color?:any):ModelMesh {
        let vi = MoldUtils.getFloorVI(data);
        return MeshHelper.updateModel(vi, data, uuid, color);
    }
}